package com.tuling.bzg.mybatis.spring;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.FactoryBean;
import sun.reflect.CallerSensitive;

/**
 * 作为mapper对象的工厂bean
 * */
public class BzgMapperFactoryBean implements FactoryBean {

    Class<?> mapperInterface;

    SqlSession sqlSession;

    public BzgMapperFactoryBean(Class<?> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public void setSqlSession(SqlSessionFactory sqlSessionFactory) {
        this.sqlSession = sqlSessionFactory.openSession();
    }

    @Override
    public Object getObject() throws Exception {
        return sqlSession.getMapper(mapperInterface);
    }

    @Override
    public Class<?> getObjectType() {
        return mapperInterface;
    }

    public static void de(){}
}
